Docker Compose interaction between profiles and depends 您所在的位置:网站首页 docker compose depends on Docker Compose interaction between profiles and depends

Docker Compose interaction between profiles and depends

#Docker Compose interaction between profiles and depends| 来源: 网络整理| 查看: 265

In the following docker-compose.yml, service "bar" depends on service "foo", but they are in different profiles. Now when I activate only profile "bar" but not profile "foo", I expect service "foo" to be started as well, however that does not happen. Is that a bug or working as intended? If it is intended, what is the reason? Is there any other way to automatically make sure that all dependencies are started as well or do I have to manually make sure that the chosen profiles do not violate my dependencies? I am using Docker version 20.10.17 with Docker Compose version 2.10.0.

services: foo: build: ./foo profiles: ["foo"] bar: build: ./bar profiles: ["bar"] depends_on: foo: condition: service_completed_successfully

P.S.: As noted by @larsks, the official documentation states:

But keep in mind that docker compose will only automatically enable the profiles of the services on the command line and not of any dependencies. This means that all services the targeted service depends_on must have a common profile with it, be always enabled (by omitting profiles) or have a matching profile enabled explicitly:

However the example code includes:

# this will fail because profile "dev" is disabled $ docker compose up phpmyadmin

The word "fail" implies to me that docker compose up bar would fail to start or at least print an error or warning but both of those don't happen.

Here is an MWE:

services: foo: image: hello-world profiles: ["foo"] bar: image: hello-world depends_on: foo: condition: service_completed_successfully $ docker compose up [+] Running 1/0 ⠿ Container test-bar-1 Created 0.1s Attaching to test-bar-1 test-bar-1 | test-bar-1 | Hello from Docker! test-bar-1 | This message shows that your installation appears to be working correctly. test-bar-1 | test-bar-1 | To generate this message, Docker took the following steps: test-bar-1 | 1. The Docker client contacted the Docker daemon. test-bar-1 | 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. test-bar-1 | (amd64) test-bar-1 | 3. The Docker daemon created a new container from that image which runs the test-bar-1 | executable that produces the output you are currently reading. test-bar-1 | 4. The Docker daemon streamed that output to the Docker client, which sent it test-bar-1 | to your terminal. test-bar-1 | test-bar-1 | To try something more ambitious, you can run an Ubuntu container with: test-bar-1 | $ docker run -it ubuntu bash test-bar-1 | test-bar-1 | Share images, automate workflows, and more with a free Docker ID: test-bar-1 | https://hub.docker.com/ test-bar-1 | test-bar-1 | For more examples and ideas, visit: test-bar-1 | https://docs.docker.com/get-started/ test-bar-1 | test-bar-1 exited with code 0

The log shows the it does not fail, it just silently executes bar without executing foo, without failing or printing a message.

P.P.S.: I created an issue at https://github.com/docker/compose/issues/9795.



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

      专题文章
        CopyRight 2018-2019 实验室设备网 版权所有